package service.clazz.strategy;

import entity.table.TableDto;
import entity.table.TableFileDto;
import entity.table.TableInfoDto;
import enums.table.ClazzTypeEnum;
import enums.table.InitImportEnum;
import service.clazz.interfaces.ClazzStrategy;
import service.common.CommonService;

import java.util.ArrayList;
import java.util.List;

/**
 * 实体类
 */
public class ClazzQueryStrategy extends ClazzStrategy {

    @Override
    public TableFileDto enerateStrategy(List<TableDto> list, TableInfoDto table) {
        TableFileDto tableFileDto = new TableFileDto();
        tableFileDto.setFileName(table.getTableNameCamel(ClazzTypeEnum.QUERY)+".java");
        tableFileDto.setContext(this.bringClazz(list, table));
        return tableFileDto;
    }

    /**
     * 生成类
     */
    private String bringClazz(List<TableDto> list, TableInfoDto table) {
        StringBuilder str = new StringBuilder();

        List<TableDto> filedList = new ArrayList<>();
        filedList.add(new TableDto("userId", "Integer", "操作人"));
        filedList.add(new TableDto("date", "Date", "操作时间"));

        // 类路径
        str.append(super.bringPackage(table.getEntityPackaging()));
        // 类引用
        str.append(super.bringImport(this.importList()));
        // 类内容
        str.append(super.bringBodyBean(ClazzTypeEnum.QUERY, table.getTableNameCamel(), filedList));
        // 输出
        return str.toString();
    }

    private List<String> importList() {
        List<String> list = InitImportEnum.initEntityList();
        list.add(InitImportEnum.Page.getClazzImport());
        list.add(InitImportEnum.PageResult.getClazzImport());
        return list;
    }
}
